<template>
<h1>循环指令</h1>
  <ul>
    <li v-for="item in 5">{{item}}</li>
  </ul>
  <ul>
    <li v-for="item in productArr">{{item}}</li>
  </ul>
  <ul>
    <table border="3px">
      <tr>
        <th>编号</th>
        <th>种类</th>
        <th>价格</th>
        <th>库存</th>
        <th>操作</th>
      </tr>
      <tr v-for="(item,index) in productArr">
        <td>{{index+1}}</td>
        <td>{{item.title}}</td>
        <td>{{item.price}}</td>
        <td>{{item.num}}</td>
        <td><button @click="del(index)">删除</button></td>
      </tr>
    </table>
  </ul>
</template>
<script setup>
import {ref} from "vue";

const productArr = ref([
  {title:'苹果',price:30,num:10},
  {title:'香蕉',price:40,num:100},
  {title:'葡萄',price:20,num:80},
  {title:'桃子',price:45,num:60},
  {title:'桃子',price:45,num:60},
  {title:'桃子',price:45,num:60},
  {title:'桃子',price:45,num:60},
  {title:'桃子',price:45,num:60}
])
const del = (index) =>{
  if (confirm('是否要删除')){
    productArr.value.splice(index,1);
  }
}
</script>


<style scoped>

</style>